package com.kakarote.hrm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kakarote.core.servlet.BaseServiceImpl;
import com.kakarote.hrm.entity.PO.HrmEmployeeChangeRecord;
import com.kakarote.hrm.mapper.HrmEmployeeChangeRecordMapper;
import com.kakarote.hrm.service.IHrmEmployeeChangeRecordService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 员工岗位/职位变更记录 服务实现类
 * </p>
 *
 * @author huangmingbo
 * @since 2020-05-12
 */
@Service
public class HrmEmployeeChangeRecordServiceImpl extends BaseServiceImpl<HrmEmployeeChangeRecordMapper, HrmEmployeeChangeRecord> implements IHrmEmployeeChangeRecordService {

    /**
     * 最新的员工改动记录
     * @param employeeId
     * @return
     */
    @Override
    public HrmEmployeeChangeRecord getLastestRecordByEmployeeId(Long employeeId){
        LambdaQueryWrapper<HrmEmployeeChangeRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HrmEmployeeChangeRecord::getEmployeeId, employeeId);
        queryWrapper.last("limit 1");
        queryWrapper.orderByDesc(HrmEmployeeChangeRecord::getCreateTime);
        HrmEmployeeChangeRecord one = this.getOne(queryWrapper);
        return one;
    }
}
